﻿using System;
using System.Threading.Tasks;
using Furion;
using Furion.Authorization;
using Furion.DatabaseAccessor;
using Furion.DependencyInjection;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using RTest.Core;

namespace RTest.Web.Core
{
    public class JwtHandler : AppAuthorizeHandler
    {
        public override Task HandleAsync(AuthorizationHandlerContext context, DefaultHttpContext httpContext)
        {
            var b = App.GetService<IRepository<Test>>();

            // 解析数据库上下文
            var dbContextResolve = App.GetService<Func<Type, IScoped, DbContext>>();
            var dbContext = dbContextResolve?.Invoke(typeof(MasterDbContextLocator), default);

            return base.HandleAsync(context, httpContext);
        }

        public override Task<bool> PipelineAsync(AuthorizationHandlerContext context, DefaultHttpContext httpContext)
        {
           
            // 这里写您的授权判断逻辑，授权通过返回 true，否则返回 false
            return Task.FromResult(true);
        }
    }
}
